from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `teacher` DROP FOREIGN KEY `fk_teacher_course_5345fb53`;
        ALTER TABLE `student` ADD `avatar_blob` LONGBLOB NOT NULL COMMENT '学生头像';
        ALTER TABLE `student` DROP COLUMN `avatar`;
        ALTER TABLE `teacher` ADD `avatar_blob` LONGBLOB NOT NULL COMMENT '教师头像';
        ALTER TABLE `teacher` DROP COLUMN `course_id_id`;
        ALTER TABLE `teacher` DROP COLUMN `avatar`;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `student` ADD `avatar` VARCHAR(255) NOT NULL COMMENT '头像URL' DEFAULT '/static/image/默认头像.png';
        ALTER TABLE `student` DROP COLUMN `avatar_blob`;
        ALTER TABLE `teacher` ADD `course_id_id` INT NOT NULL;
        ALTER TABLE `teacher` ADD `avatar` VARCHAR(255) NOT NULL COMMENT '头像URL' DEFAULT '/static/image/默认头像.png';
        ALTER TABLE `teacher` DROP COLUMN `avatar_blob`;
        ALTER TABLE `teacher` ADD CONSTRAINT `fk_teacher_course_5345fb53` FOREIGN KEY (`course_id_id`) REFERENCES `course` (`id`) ON DELETE CASCADE;"""
